import type { BuildOptions } from 'vite'
import type { PreRenderedAsset } from 'rollup'

/** @type {import('vite').UserConfig} */
export default {
  // share Options:https://vite.dev/config/shared-options.html
  target: 'modules',
  outDir: 'dist',
  sourcemap: false,
  manifest: false,
  // lightningcss: https://lightningcss.dev/minification.html
  cssMinify: 'lightningcss', // 需要注意与postcss的兼容
  minify: 'terser',
  reportCompressedSize: false,
  rollupOptions: {
    output: {
      entryFileNames: 'ml-js/[name].js',
      chunkFileNames: 'ml-js/[name]-[hash:10].js',
      assetFileNames: (assetInfo: PreRenderedAsset) => {
        // console.log('names', assetInfo)
        const ext = assetInfo.name?.split('.').pop()
        if (ext === 'css') {
          return 'ml-style/[name]-[hash:10][extname]'
        }
        return 'ml-assets/[name]-[hash:10][extname]'
      },
    },
  },
} satisfies BuildOptions
